﻿// <copyright file="QldFederalStateElectorateMappingFileDefinition.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

using System;
using System.IO;
using FileHelpers;
using FileHelpers.DataLink;

namespace Qut.GenerateKml.Data.FileDefinitions
{
    /// <summary>
    /// Represents the structure of the Qld_Federal-State Electorate Mapping.xls data file.
    /// </summary>
    [DelimitedRecord("|")]
    public class QldFederalStateElectorateMappingFileDefinition
    {
        /// <summary>
        /// Gets or sets the Federal Seat
        /// </summary>
        public string FederalSeat { get; set; }

        /// <summary>
        /// Gets or sets the State Seat
        /// </summary>
        public string StateSeat { get; set; }

        /// <summary>
        /// Loads the specified data file from the file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="db">The data context.</param>
        public static void Load(string filePath, SociologicalDataClassesDataContext db)
        {
            var provider = new ExcelStorage(typeof(QldFederalStateElectorateMappingFileDefinition), filePath, 2, 1);
            var results = provider.ExtractRecords() as QldFederalStateElectorateMappingFileDefinition[];
            db.TruncateQldFederalStateElectorateMapping();
            foreach (var item in results)
            {
                var record = new QldFederalStateElectorateMapping();
                record.FederalSeat = item.FederalSeat;
                record.StateSeat = item.StateSeat;
                db.QldFederalStateElectorateMappings.InsertOnSubmit(record);
            }

            db.SubmitChanges();
        }
    }
}
